import {
  request,
  makePhoneCallHandler,
  navigationHandler
} from '../../utils/requestUtils';

import {
  userBehavior
} from '../../behaviors/userBehavior'

Page({
  behaviors: [userBehavior],
  data: {
    show: false, // 期望送达日期弹框
    minDate: new Date().getTime(),
    currentDate: new Date().getTime(),
    form: {
      customerName: '',
      contact: '',
      payableAmount: '0',
      deliveryDate: '', //送达日期
      deliveryStr: '', //送达时间点
      remark: '',
      addrId: '', //地址id
      lines: [], //行信息
    },
    addr: {
      id: '',
    }
  },
  onShow() {


  },


  onLoad(options) {
    console.log('options', options)
    if (options.id) {
      this.getOrderById(options.id)
    }
  },

  // 导航去客户
  async navigationToCustomer(event){
    await navigationHandler(this.data.form.addr.latitude,this.data.form.addr.longitude,this.data.form.addr.attr1+this.data.form.addr.defineAddr)
  },
    // 导航去商家
    async navigationToMerchant(event){
      await navigationHandler(this.data.form.groupStall.latitude,this.data.form.groupStall.longitude,this.data.form.groupStall.location)
    },
      //拨打电话
  async makeCustomerPhoneCall(){
    let result = await makePhoneCallHandler(this.data.form.addr.contactPhone)
  },
  async makeMerchantPhoneCall(){
    let result = await makePhoneCallHandler(this.data.form.groupStall.telephone)
  },
  

  //获取订单信息
  async getOrderById(id) {
    const result = await request({
      url: `/merchant/merchant_return_order/` + id,
      method: "GET",
      data: {}
    })
    if (result.data.code == 200) {
      this.setData({
        form: result.data.data
      })
    }
  },
   // 取货 1;送达 2
   operate(event){
    let component = this.selectComponent('#operate')
    if (component) {
      component.showhandler({
        id: this.data.form.id,
        type: event.target.dataset.type
      });
    }
  },
  // 返回上一步
  onScrollRefresh(){
    wx.navigateBack({
      delta: 1
    })
  }
})